﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Collections;
using TierApplication;
using System.Web.Security;

public partial class left : System.Web.UI.Page
{
    P_Moudle _Moudle = new P_Moudle();
    protected void Page_Load(object sender, EventArgs e)
    {
        // 在此处放置用户代码以初始化页面
        if (!Page.IsPostBack)
        {
            LoadMenusHtml();
        }

    }
    private void LoadMenusHtml()
    {

        string strTitle = "";
        string strMenus = "";
        //string strUserName = "Admin";

        GetMenuHtml("administrator", (long)100, ref strTitle, ref strMenus);

        litMenuTitle.Text = strTitle;
        litMenus.Text = strMenus;
    }
    /// <summary>
    /// 获取普通用户菜单HTML
    /// </summary>
    /// <param name="lngUserID"></param>
    /// <param name="strHeader"></param>
    /// <param name="strMens"></param>
    public void GetMenuHtml(string strUserName, long lngUserID, ref string strHeader, ref string strMens)
    {
        StringBuilder sb = new StringBuilder("");

        StringBuilder sbTitle = new StringBuilder("");

        List<MoudleInfo> list = this._Moudle.GetMoudleByRole(Authentication.GetUserRole());

        list = list.FindAll(delegate(MoudleInfo info1)
        {
            return info1.ParentId == "0";
        });

        sb.Append(@"<table class=""navContent"" height=""100%"" cellSpacing=""0"" cellPadding=""0"" width=""96%"" align=""center""
                                    border=""0"">
                                    <tr>
                                        <td vAlign=""top"" bgColor=""#ffffff"" height=""100%""><iframe id=""frameColumnNav"" style=""WIDTH: 100%; HEIGHT: 100%"" onfocus=""this.blur();"" border=""0""
                                                name=""frameColumnNav"" marginWidth=""0"" marginHeight=""0"" src=""submenu.aspx?username=" + strUserName + "&mid=" + list[0].MoudleId + @""" frameBorder=""0"" scrolling=""auto""></iframe>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style=""CURSOR: hand"" onclick=""setNavMenu();"" vAlign=""bottom"" align=""center"" background=""images/Menus/bg_middle1_main.gif""
                                            height=""5""><IMG height=""5"" src=""images/Menus/bg_middle1_button.gif""></td>
                                    </tr>
                                    <tr id=""navMenu"" name=""navMenu"">
                                        <td vAlign=""bottom"" bgColor=""#ffffff"" height=""0px"">
                                            <table id=""tableNAV"" cellSpacing=""0"" cellPadding=""0"" width=""100%"" align=""center"" border=""0""
                                                name=""tableNAV"">");




        int i = 1;
        foreach (MoudleInfo info in list)
        {
            sb.Append(@"<tr><td align=""left"" onmouseover=""setNavMenuBGMove(" + i.ToString() + @")"" 
                               onmouseout=""setNavMenuBGOut(" + i.ToString() + @")""
                             class=""" + (i == 1 ? "navColumnLight" : "navColumnDark") + @""" id=""navMenu" + i.ToString() + @""" style=""height: 25px""
                             onclick=""navTitleDiv.innerHTML='" + info.MoudleName + @"';document.all.frameColumnNav.src='submenu.aspx?username=" + strUserName + "&mid=" + info.MoudleId + @"';
                                                     setNavMenuBG(" + i.ToString() + @")""
                                 ><IMG src=""" + info.Img + @""" width=""16"" align=""absMiddle"">
                                                        <A href=""#"">" + info.MoudleName + @"</A>
                                                    </td>
                                                </tr>");
            if (i == 1)
                sbTitle.Append(@"<div class=""navTitle"" id=""navTitleDiv"" name=""navTitleDiv"">" + info.MoudleName + @"</div>");
            i++;
        }

        sb.Append(@"</table>
                                            <table id=""tableNavIndex"" cellSpacing=""0"" cellPadding=""0"" width=""100%"" border=""0"" name=""tableNavIndex"">
                                                <tr>
                                                    <td class=""navColumnDark"" id=""navMenuIndex"" style=""DISPLAY: none"" height=""25"">
                                                        <div align=""center"" width=""100%""> ");
        i = 1;
        foreach (MoudleInfo info in list)
        {
            sb.Append(@"<A onclick=""navTitleDiv.innerHTML='" + info.MoudleName + @"';document.all.frameColumnNav.src='submenu.aspx?username=" + strUserName + "&mid=" + info.MoudleId + @"';setNavMenuBG(" + i.ToString() + @")""
                                                                href=""#""><IMG title=""" + info.MoudleName + @""" src=""" + info.Img + @""" width=""16"" align=""absMiddle""
                                                                    border=""0""></A> ");
            i++;
        }

        sb.Append(@"</div>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>");

        strHeader = sbTitle.ToString();
        strMens = sb.ToString();
    }
}
